<%@page import="java.net.URL"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="h" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ page import="limousine.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>

        <link rel="stylesheet" type="text/css" href="../app/css/style.css"/>
        <script language="JavaScript" type="text/JavaScript" src="../app/js/func.js"></script>
        <script language="JavaScript" type="text/JavaScript" src="../app/js/form.js"></script>

    </head>
    <body>

        <script language="JavaScript" type="text/JavaScript" src="../app/js/wz_tooltip.js"></script>

        <h:form action="/uploadimageinsert.do" method="post" enctype="multipart/form-data">
            <table class="tableForm">
                <tr><td class="textFormLabel" align="center" colspan="2">
                        <jsp:include page="sys_msg.jsp" />
                    </td>
                </tr>
                <tr><td class="textFormLabel" align="right" width="20%">Category:</td>
                    <td align="left">
                        <h:select property="category" styleClass="combo">
                            <logic:present name="<%=Token.UPLOAD_IMAGE_CATEGORY_LIST%>">
                                <logic:iterate id="funcs" scope="session" type="limousine.util.SelectItem"
                                name="<%=Token.UPLOAD_IMAGE_CATEGORY_LIST%>">
                            <option value="<%=funcs.getKey()%>"  <%=(funcs.getSelect()) ? "selected" : ""%> ><%=funcs.getValue()%></option>
                        </logic:iterate>
                    </logic:present>
                </h:select>
                Type
                <h:select property="type" styleClass="combo">
                    <logic:present name="<%=Token.UPLOAD_IMAGE_TYPE_LIST%>">
                        <logic:iterate id="funcs" scope="session" type="limousine.util.SelectItem"
                        name="<%=Token.UPLOAD_IMAGE_TYPE_LIST%>">
                            <option value="<%=funcs.getKey()%>"  <%=(funcs.getSelect()) ? "selected" : ""%> ><%=funcs.getValue()%></option>
                        </logic:iterate>
                    </logic:present>
                </h:select>
            </td>
        </tr>
        <tr><td class="textFormLabel" align="right" width="20%">Choose File :
            </td>
            <td align="left">
                <h:file property="iFile" size="45" styleClass="textBox"/>
                <input type="button" value="Upload" onclick="javascription:checkFill(this.form);"/>
                <h:hidden property="name" />
            </td>
        </tr>
        <tr height="5"><td class="text" align="center" colspan="2">
            </td>
        </tr>
    </table>
</h:form>


<center><a href="" OnClick="window.close()">Close Window</a></center>
<!-- record -->
<logic:present name="<%=Token.UPLOAD_IMAGE%>">

    <table width="100%"  border="0" cellspacing="0" cellpadding="10" >
        <tr>
            <td>
                <fieldset class="bold-th">
                    <legend><strong>Image Temp</strong></legend>
                    <div style="overflow: auto;">
                        <table width="100%" cellspacing="1" cellpadding="1" border="0">
                            <tbody><tr valign="top" align="center">
                                    <th bgcolor="#666666">ลำดับที่</th>
                                    <th bgcolor="#666666">URL</th>
                                    <th bgcolor="#666666">ลบ</th>
                                </tr>
                                <%
                                            int countRow = 1;
                                            Func func = new Func();

                                            /*URL fullContext = new URL(request.getScheme(), request.getServerName(),
                                                    request.getServerPort(), request.getContextPath());*/
                                            String contextUrl = "http://km.mrta.co.th/MRTA";
                                            
                                %>

                                <logic:iterate id="bean" scope="session" type="limousine.vo.Image" name="<%=Token.UPLOAD_IMAGE%>">
                                    <tr bgcolor="#f0f0f0" onmouseout="this.bgColor='#F0F0F0'" onmouseover="this.bgColor='#CCCC99'">
                                        <td align="center" width="8%" ><%=countRow%></td>
                                        <td valign="center" ><img src="images/look.gif" onmouseover="javascript:Tip('<img src=<%=contextUrl%>/showImg?id=<%=bean.getId()%>&w=80&h=80 />');" />
                                            &nbsp;<%=contextUrl%>/showImg?id=<%=bean.getId()%>
                                        </td>
                                        <td align="center" width="5%" >
                                            <a href="#" id="D<%=bean.getId()%>" onclick="javascript:goDelete('../uploadimagedelete.do?did=<%=bean.getId()%>&catLock=1','D<%=bean.getId()%>','Confirm remove [<%=func.displayTextByLenght(bean.getName(), 70)%>]');" >
                                                <img src="images/delete.gif" border="0" alt="D<%=bean.getId()%>"/>
                                            </a>
                                        </td>
                                    </tr>
                                    <%countRow++;%>
                                </logic:iterate>
                            </tbody>
                        </table>
                    </div>
                </fieldset>
            </td>
        </tr>
    </table>
    <center><a href="" OnClick="window.close()">Close Window</a></center>
</logic:present>
<!-- record -->



</body>
</html>

<script type="text/javascript">
    window.onload = function() {
        document.forms[0].category.disabled=true;
    }

    function checkFill(obj){
        clearWarningMsg();
        clearSystemMsg();


        if(!checkSelectBoxValue(obj.category,"category"))return;
        if(!checkSelectBoxValue(obj.type,"type"))return;

        if(obj.iFile.value == ""){
            addWarningMsg('Please choose file for upload.');
            setFocusTextBox(obj.iFile);
            return false;
        }
        if(!checkTextBoxValue(obj.iFile,"File"))return;

        obj.name.value = obj.iFile.value;
/*
        var extension = obj.iFile.value.split(".");
        var extensionList=["jpg","gif","bmp","png"];
        var support = false;        
        if(extension.length > 0){
            for(var i=0;i<extensionList.length;i++){
                if(extension[extension.length-1].toLowerCase() == extensionList[i]){
                support = true;
                break;
                }
            }
        }        
        if(!support){
            addWarningMsg('Invalid file. System support only ['+extensionList+']');
            setFocusTextBox(obj.iFile);
            return false;
        }
*/
        var extensionList=["jpg","gif","bmp","png"];
        if(!checkFileSupport(obj.iFile,extensionList)){
            return false;
        }
       
        //alert("OK");
        onSubmit(obj);
    }
</script>
